// pages/detail/detail.js
const http = require('../../utils/http');
Page({

  /**
   * 页面的初始数据
   */
  data: {
      musics:[]
      
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    this.audioCtx = wx.createAudioContext('myAudio');
    var data = await http(`playlist/detail?id=${options.id}`);
    var tracks = data.data.playlist.tracks;
    var musics = [];
    tracks.forEach(async element => {
        var obj = {};
        obj.name = element.name.slice(0,5);
        obj.author = element.ar[0].name;
        obj.poster = element.al.picUrl
        obj.id = element.id;
        musics.push(obj);
    });
    this.setData({
      musics
    })
  },
  handleClick(event){
    var {id,name,poster} = event.currentTarget.dataset;
    wx.setStorageSync("poster",poster)
    wx.navigateTo({
      url: `/pages/music/music?id=${id}&name=${name}`
    })
  }
})